﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SchoolManagementSystem.Controls;

using CoreData;
using Helper;
namespace SchoolManagementSystem.DetailsManager
{
    public partial class ModuleUC : DetailUC
    {
        public ModuleUC()
        {
            InitializeComponent();
            this.ObjectName = "chức năng";
            this.Code = "Module";
            this.Type = new Module();
        }

        
       

        protected override long DetailDisplay()
        {
            Module module = new Module();
            if(ID>0)
            {
                module = (Module)RegisterService.RegisterServices.ModuleService.GetByID(ID);
            }
            txtcode.Text = module.Code;
            txtname.Text = module.Name;
            txtdescription.Text = module.Description;
            ckactive.Checked = module.Active;
            return ID;
            
        }

        protected override long Save()
        {
            Module module = new Module();
            if (ID > 0)
            {
                module = (Module)RegisterService.RegisterServices.ModuleService.GetByID(ID);
            }
            module.ModuleGuidID = Guid.NewGuid().ToString();
            module.Code = txtcode.Text;
            module.Name = txtname.Text;
            module.Description = txtdescription.Text;
            module.Active = ckactive.Checked;
            ID = RegisterService.RegisterServices.ModuleService.Save(module);
            return ID;
        }


        public override bool Delete(long SelectedID)
        {
            return RegisterService.RegisterServices.ModuleService.Delete((Module)RegisterService.RegisterServices.ModuleService.GetByID(SelectedID));
           
        }

     
       

        private void ModuleUC_Load(object sender, EventArgs e)
        {
            AddTextChanged(this.groupControl1.Controls);
        }

    }
}
